package com.hw.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hw.shortlink.project.common.convention.response.Result;
import com.hw.shortlink.project.common.convention.response.Results;
import com.hw.shortlink.project.dto.req.RecycleBinPageReqDto;
import com.hw.shortlink.project.dto.req.RecycleBinRecoverDto;
import com.hw.shortlink.project.dto.req.RecycleBinRemoveReqDto;
import com.hw.shortlink.project.dto.req.RecycleBinSaveReqDto;
import com.hw.shortlink.project.dto.resp.ShortLinkPageRespDto;
import com.hw.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;


    /**
     * 将短链接移至回收站
     * @return
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveToRecycleBin(@RequestBody RecycleBinSaveReqDto recycleBinSaveReqDto){
        recycleBinService.saveToRecycleBin(recycleBinSaveReqDto);
        return Results.success();
    }

    /**
     * 回收站分页查询
     * @param recycleBinPageReqDto
     * @return
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<ShortLinkPageRespDto>> pageQuery(RecycleBinPageReqDto recycleBinPageReqDto){
        return Results.success(recycleBinService.pageQuery(recycleBinPageReqDto));
    }

    /**
     * 复原短链接
     * @param recycleBinRecoverDto
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recover(@RequestBody RecycleBinRecoverDto recycleBinRecoverDto){
        recycleBinService.recover(recycleBinRecoverDto);
        return Results.success();
    }

    /**
     * 删除回收站中的短链接
     * @param recycleBinRemoveReqDto
     * @return
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDto recycleBinRemoveReqDto) {
        recycleBinService.removeRecycleBin(recycleBinRemoveReqDto);
        return Results.success();
    }
}
